package com.wn.controller;

import com.wn.annotation.RequireRoles;
import com.wn.entity.Guideinfo;
import com.wn.service.GuideinfoService;
import com.wn.utils.PageParam;
import com.wn.utils.Rsp;
import com.wn.utils.SystemControllerLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (Guideinfo)表控制层
 *
 * 导游信息管理
 * @author makejava
 * @since 2020-10-26 09:30:01
 */
@RestController
@RequestMapping("guideinfo")
@Api(value = "导游信息管理接口",description="导游信息管理接口")
public class GuideinfoController {
    /**
     * 服务对象
     */
    @Resource
    private GuideinfoService guideinfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Guideinfo selectOne(String id) {
        return this.guideinfoService.queryById(id);
    }

    @SystemControllerLog(description = "分页查询导游列表")
    @PostMapping("/searchSomeGuideByPage")
    @RequireRoles(roles = {"admin","super_admin","reception","tourist"},index = 1)
    @ApiOperation("查询所有用户 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Guideinfo> guideinfoPageParam,
                                @RequestHeader("token") String token){

        return Rsp.success(guideinfoService.queryAllByLimit(guideinfoPageParam));
    }


    @SystemControllerLog(description = "添加导游信息")
    @RequireRoles(roles = {"admin","super_admin"},index = 1)
    @PostMapping("/addOneGuide")
    public Rsp addOne(@RequestBody @Valid Guideinfo guideinfo,
                      @RequestHeader("token") String token){

        return guideinfoService.insert(guideinfo);
    }

    @SystemControllerLog(description = "逻辑删除导游")
    @RequireRoles(roles = {"admin","super_admin"},index = 1)
    @PostMapping("/deleteGuideLogical")
    public Rsp deleteUserLogical(@RequestBody Guideinfo guideinfo,
                                 @RequestHeader("token") String token){

        return guideinfoService.deleteLogical(guideinfo);
    }

    @SystemControllerLog(description = "修改导游信息")
    @RequireRoles(roles = {"admin","super_admin"},index = 1)
    @PostMapping("/updateGuide")
    public Rsp updateUser(@RequestBody Guideinfo guideinfo,
                          @RequestHeader("token") String token){

        return guideinfoService.update(guideinfo);
    }

}
